package com.haoxuewa.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haoxuewa.entity.EssayTemp;
import com.haoxuewa.service.EssayService;
import com.haoxuewa.service.EssayTempService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/backstage")
public class EssayTempController {

    private final EssayTempService essayTempService;


    @Autowired
    public EssayTempController(EssayTempService essayTempService) {
        this.essayTempService = essayTempService;
    }

    /**
     * 文章审核的展示列表
     *
     * @return 分页后的文章标题列表
     */
    @GetMapping("/getAuditEssayList")
    public String getAuditEssayList(@RequestParam("pageNum") int pageNum) {
        JSONObject jsonObject = new JSONObject();
        int pageSize = 10;
        Page<EssayTemp> essayList = essayTempService.getAuditEssayList(pageNum, pageSize);
        jsonObject.put("总页数", essayList.getPages());
        jsonObject.put("当前页数",essayList.getTotal());
        jsonObject.put("当前页面记录数量", essayList.getSize());
        jsonObject.put("resultList", essayList.getRecords());
        return jsonObject.toString();
    }

    @GetMapping("/getAuditEssayContent")
    public String getAuditEssayContent(@RequestParam("essayId") int essayId) {
        return new JSONObject(essayTempService.getAuditEssayContent(essayId)).toString();
    }

}
